import request from '@/utils/request';
import type { Borrow, BorrowQueryParams, BorrowRequest } from '@/types/borrow';
import type { PageResult } from '@/types/book';
import type { ApiResponse } from '@/types/user';

// 借阅图书
export const borrowBook = (data: BorrowRequest): Promise<ApiResponse<Borrow>> => {
  return request.post('/borrows', data);
};

// 归还图书
export const returnBook = (borrowId: number): Promise<ApiResponse<Borrow>> => {
  return request.put(`/borrows/${borrowId}/return`);
};

// 借阅记录查询
export const getBorrowList = (params: BorrowQueryParams): Promise<ApiResponse<PageResult<Borrow>>> => {
  return request.get('/borrows', { params });
};
